package com.jltx.xq.simplewatch.news.api;

import com.jltx.xq.simplewatch.commons.ApiConstants;
import com.jltx.xq.simplewatch.utils.GsonFactoryUtils;
import com.jltx.xq.simplewatch.utils.OkhttpClientFactoryUtils;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * @author jltxseo
 * @date 2017/09/05.
 * @description:
 */

public class TopicNewsApiService {
    private Retrofit retrofit;
    private TopicNewsApi topicNewsApi;

    private TopicNewsApiService() {

        retrofit = new Retrofit.Builder()
                .baseUrl(ApiConstants.TOPICNEWS_BASE_URL)
                .client(OkhttpClientFactoryUtils.getInstance().getOkHttpClient())
                .addConverterFactory(ScalarsConverterFactory.create())
                .addConverterFactory(GsonFactoryUtils.providerGsonConverterFactory())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();

        topicNewsApi = retrofit.create(TopicNewsApi.class);

    }

    public TopicNewsApi getTopicNewsApi() {
        return topicNewsApi;
    }

    public static TopicNewsApiService getInstance(){
        return TopicNewsApiServiceHolder.sInstance;
    }

    private static class TopicNewsApiServiceHolder{
        private static final TopicNewsApiService sInstance = new TopicNewsApiService();
    }
}
